package com.briup.demo.service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.demo.bean.XcdBuyer;
import com.briup.demo.mapper.XcdBuyerMapper;

@Service
public class XcdBuyerService {
	
	@Autowired
	private XcdBuyerMapper buyerMapper;

	public int saveOrUpdateCmsCategory(XcdBuyer buyer) {
		if(buyer.getBuyerid()!=null&&!"".equals(buyer.getBuyerid())) {
			if(null!=buyerMapper.selectByPrimarykey(buyer.getBuyerid())) {
				buyerMapper.updateByPrimaryKey(buyer);	
				return 1;
			}else {
				buyerMapper.insert(buyer);
				return 0;
			}
		}else {
			buyer.setBuyerid(UUID.randomUUID().toString());
			buyerMapper.insert(buyer);
			return 0;
		}
	}
	
    public XcdBuyer selectById(String id)
    {
        return  buyerMapper.selectByPrimarykey(id);
    }

    public int deleteById(String id){
        return buyerMapper.deleteByPrimaryKey(id);

    }
    
    public int deleteByIds(String[] ids) {
    	int count = 0;
    	for(String id:ids) {
    		int num = deleteById(id);
    		if(num == 1) {
    			count++;
    		}
    	}
    	return count;
    }
    

    public List<XcdBuyer> selectAll(){
        List<XcdBuyer> list = buyerMapper.selectAll();
		if(list!=null) {
			return list;
		}
		return new ArrayList<XcdBuyer>();
	}

	public List<XcdBuyer> selectByName(String name) {
		
        List<XcdBuyer> list = buyerMapper.selectByName(name);
		if(list!=null) {
			return list;
		}
		return new ArrayList<XcdBuyer>();
	}
    

}

